package me.stone.stanimeclient.core.common.extensions

import java.util.Collections


fun <K, V, TK, TV> Map<K, V>.mapKV(
    block: (Map.Entry<K, V>) -> Pair<TK, TV>
): Map<TK, TV> {
    val mutableMap = mutableMapOf<TK, TV>()
    forEach { entry ->
        val newEntry = block(entry)
        mutableMap[newEntry.first] = newEntry.second
    }
    return Collections.unmodifiableMap(mutableMap)
}

operator fun <K, V> Map<K, V>.plus(pair: Pair<K, V>): Map<K, V> {
    val mutableMap = mutableMapOf<K, V>()
    mutableMap.putAll(this)
    mutableMap[pair.first] = pair.second
    return Collections.unmodifiableMap(mutableMap)
}